/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.TCube;

import session.TX.DishManagerSBRemote;
import session.TX.OutletSBRemote;
import entity.FoodItem;
import entity.Outlet;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

/**
 *
 * @author Lu Xiaodi
 */
@ManagedBean(name = "dishManagedBeanTCube")
@ViewScoped
public class DishManagedBeanTCubeMB {

    @EJB
    DishManagerSBRemote dishBean;
    @EJB
    OutletSBRemote outletBean;
    Long itemId;
    Long outletId;
    List<Outlet> allOutlets;
    private SelectItem[] lockedOptions;
    private List<SelectItem> dishTypeOptions;

    /** Creates a new instance of DishManagedBeanTCubeMB */
    public DishManagedBeanTCubeMB() {
        lockedOptions=this.generateLockedOptions();
        dishTypeOptions=this.generateDishTypes();
    }

    public List<Outlet> getAllOutlets() {
        return outletBean.getAllOutlets();
    }

    public List<FoodItem> getAllPromotionDishes() {
        return dishBean.getAllPromotionalDishes();
    }

    public List<FoodItem> getAllDishes() {
        System.out.println("im here..");
        if (outletId == null) {
            //throw outletId not found exception
            return null;
        }
        return dishBean.getNonDeliItemForSale(outletId);
    }

    public void lockDish(ActionEvent event) {
        Long id = (Long) event.getComponent().getAttributes().get("dishId");
        dishBean.lockFoodItem(id);
    }

    public void unlockDish(ActionEvent event) {
        Long id = (Long) event.getComponent().getAttributes().get("dishId");
        dishBean.unlockFoodItem(id);
    }

    //getter and setters
    public Long getItemId() {
        return itemId;
    }

    public void setItemId(Long itemId) {
        this.itemId = itemId;
    }

    public Long getOutletId() {
        return outletId;
    }

    public void setOutletId(Long outletId) {
        this.outletId = outletId;
    }

    public List<SelectItem> getDishTypeOptions() {
        return dishTypeOptions;
    }

    public void setDishTypeOptions(List<SelectItem> dishTypeOptions) {
        this.dishTypeOptions = dishTypeOptions;
    }

    public SelectItem[] getLockedOptions() {
        return lockedOptions;
    }

    public void setLockedOptions(SelectItem[] lockedOptions) {
        this.lockedOptions = lockedOptions;
    }

    private SelectItem[] generateLockedOptions() {
        SelectItem[] returnItems = new SelectItem[]{
            new SelectItem("", "Select"),
            new SelectItem("True", "Yes"),
            new SelectItem("False", "No")
        };
        return returnItems;
    }

    private List<SelectItem> generateDishTypes() {
        List<SelectItem> returnList = new ArrayList<SelectItem>();
        returnList.add(new SelectItem("", "Select"));
        for (String t : FoodItem.getAllTypes()) {
            returnList.add(new SelectItem(t, t));
        }
        return returnList;
    }
}
